//
//  NSArray+WCExtensions.m
//  WabbitCode
//
//  Created by William Towe on 11/9/08.
//  Copyright 2008 Revolution Software. All rights reserved.
//

#import "NSArray+WCExtensions.h"
#import "NSDictionary+WCExtensions.h"


@implementation NSArray (WCExtensions)
- (id)firstObject; {
	if (![self count])
		return nil;
	return [self objectAtIndex:0];
}

- (NSArray *)sortDescriptorsFromDictionaries; {
	NSMutableArray *sds = [NSMutableArray array];
	
	for (NSDictionary *dict in self)
		[sds addObject:[dict sortDescriptorFromDictionary]];
	
	return [[sds copy] autorelease];
}

- (NSIndexSet *)indexSetFromArray; {
	NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
	
	for (NSNumber *index in self)
		[indexSet addIndex:[index unsignedIntegerValue]];
	
	return [[indexSet copy] autorelease];
}

+ (id)arrayWithSet:(NSSet *)set; {
	NSMutableArray *temp = [NSMutableArray array];
	for (id object in set)
		[temp addObject:object];
	return [[temp copy] autorelease];
}
@end


@implementation NSMutableArray (WCExtensions)
- (void)removeFirstObject; {
	[self removeObject:[self firstObject]];
}

- (void)replaceObject:(id)objectToRemove withObject:(id)object; {
	NSUInteger index = [self indexOfObject:objectToRemove];
	if (index == NSNotFound)
		return;
	
	[self replaceObjectAtIndex:index withObject:object];
}
@end